package org.example.controller;

import org.example.model.Major;
import org.example.model.Menu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ ClassName: PageController
 * @ Description：请求服务端page的接口
 * @ Modified By：
 * @ Version:
 * @ Author     ：LiYing
 * @ Date       ：Created in 16:21 2022/4/25
 */

@Controller
@RequestMapping(value = "/page")
public class PageController {
    @Autowired
    private LoadBalancerClient loadBalancerClient;
    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping(value = "/getSecondLevelMenu")
    public @ResponseBody List<Menu> getFirstLevelMenu(HttpServletRequest request) {
        int role = Integer.parseInt(request.getParameter("role"));
        List<Menu> forObject = restTemplate.getForObject("http://EUREKA-SERVICE/page/getSecondLevelMenu?role=" + role, List.class);
        return forObject;
    }
}
